package cn.itlaobing.management.service.impl;

import cn.itlaobing.management.common.ResponseInfo;
import cn.itlaobing.management.entity.User;
import cn.itlaobing.management.mapper.UserMapper;
import cn.itlaobing.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 马浩 1085473391@qq.com
 * @Package cn.itlaobing.management.service.impl
 * @Description: TODO (  )
 * @Date 2019/4/8 15:25
 * @Version V1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public User getOne(User user) {
        return userMapper.selectByNameAndPass(user);
    }

    @Override
    public ResponseInfo doLogin(User user) {
        if (StringUtils.isEmpty(user) || StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getPassword())){
            return ResponseInfo.error("请输入账号或者密码");
        }
        User userDB = getOne(user);
        if(StringUtils.isEmpty(userDB)){
            return ResponseInfo.error("账号或密码不正确");
        }else{
            ResponseInfo info = ResponseInfo.ok();
            info.msg = "/index";
            info.setData(userDB);
            return info;
        }
    }
}
